package com.dreamoo.controller.user;

import cn.hutool.system.UserInfo;
import com.dreamoo.common.pojo.dto.DreamAnalysisDTO;
import com.dreamoo.common.pojo.vo.DreamAnalysisVO;
import com.dreamoo.common.pojo.vo.DreamVO;
import com.dreamoo.common.pojo.vo.UserLoginVO;
import com.dreamoo.common.result.Result;
import com.dreamoo.common.threadlocal.BaseParameterHolder;
import com.dreamoo.common.threadlocal.ThreadLocalConstant;
import com.dreamoo.service.AiDreamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Objects;

/**
 * @author 山顶洞人郑某
 * @className AiDreamController.java AI梦境分析
 * @date 2025 05 09
 */
@RestController
@RequestMapping("/dreamoo/ai")
@Tag(name = "AI梦境分析控制层")
@Slf4j
public class AiDreamController {


    @Autowired
    private AiDreamService aiDreamService;

    /**
     * 梦境解析
     * @param dreamAnalysisDTO 梦境解析参数
     * @return 梦境解析结果
     */
    @Operation(summary = "AI梦境解析")
    @ApiResponse(description = "AI梦境解析")
    public Result<DreamVO> analysisDream(DreamAnalysisDTO dreamAnalysisDTO) {
        if (dreamAnalysisDTO == null) {
            return Result.error("梦境解析参数不能为空");
        }
        String userId = String.valueOf(
                Objects.requireNonNull(BaseParameterHolder.get(ThreadLocalConstant.USER_LOGIN_INFO, UserLoginVO.class))
                        .getId());
        log.info("AI梦境解析：{},用户Id是{}",dreamAnalysisDTO,userId);
        DreamVO dreamVO =  aiDreamService.analysisDream(dreamAnalysisDTO, userId);
        log.info("梦境解析结果是{}",dreamVO);
        return Result.success(dreamVO);
    }


    @Operation(summary = "梦境解析详细结果{流式传输}")
    @ApiResponse(description = "梦境解析详细结果{流式传输}")
    public Flux<String> analysisDreamStream() {
        log.info("AI梦境解析：{}", "流式传输");
        return null;
    }

}
